package com.itheima.convert;

import com.itheima.dto.CommentDto;
import com.itheima.entity.Comment;
import com.itheima.vo.CommentVo;
import com.itheima.vo.comment.CommentChildVo;
import com.itheima.vo.comment.CommentParentVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * <h1>评论转换接口</h1>
 *
 * @author <a href="515857087@qq.com">叶世铭</a>
 * @since 2022/12/2
 */
@Mapper(componentModel = "spring")
public interface CommentConvert {

    /**
     * Comment -> CommentVO
     *
     * @param comment
     * @return
     */
    @Mappings(
            @Mapping(target = "time", ignore = true)
    )
    CommentVo commentToCommentVo(Comment comment);

    /**
     * CommentDto -> Comment
     *
     * @param commentDto
     * @return
     */
    Comment commentDtoToComment(CommentDto commentDto);

    /**
     * List<Comment> list -> List<CommentParentVo>
     *
     * @param list 评论实体
     * @return 父评论VO
     */
    List<CommentParentVo> toCommentParentVo(List<Comment> list);

    /**
     * Comment -> CommentChildVo
     *
     * @param parentComment 父评论
     * @param childComment  子评论
     * @return 子评论Vo
     */
    @Mappings({
            @Mapping(target = "userId", source = "childComment.userId"),
            @Mapping(target = "messageId", source = "childComment.messageId"),
            @Mapping(target = "id", source = "childComment.id"),
            @Mapping(target = "content", source = "childComment.content"),
            @Mapping(target = "createdAt", source = "childComment.createdAt"),
            @Mapping(target = "replyUserId", source = "parentComment.userId"),
            @Mapping(target = "replyContent", source = "parentComment.content")
    })
    CommentChildVo toCommentChildVo(Comment parentComment, Comment childComment);
}
